package moxl.parser.assemblers.xmldecl;

import moxl.parser.ParserException;
import moxl.parser.assemblers.AbstractTokenFedMarkupAssembler;
import moxl.parser.assemblers.AssemblerException;
import moxl.tokenizer.TokenStream;
import moxl.tokenizer.TokenizerException;
import moxl.tokenizer.xml.XmlTokenType;

public class XmlDeclarationAssembler extends AbstractTokenFedMarkupAssembler<XmlDeclarationAssemblerState, XmlDeclarationAssemblerContext>
{
	@Override
	protected XmlDeclarationAssemblerContext createAssemblerContext(TokenStream tstream)
	{
		return new XmlDeclarationAssemblerContext(tstream);
	}

	@Override
	protected void handleInput(XmlTokenType type, XmlDeclarationAssemblerContext ctx) throws ParserException, TokenizerException
	{
		XmlDeclarationStateDelegateBase delegate = ctx.getState().getDelegate();
		switch (type)
		{
		case OPEN_CHEVRON_QUESTION_MARK:
			delegate.acceptOpenChevronQuestionMark(ctx);
			break;
		
		case NAME:
			delegate.acceptName(ctx);
			break;

		case SINGLE_QUOTE:
			delegate.acceptSingleQuote(ctx);
			break;

		case DOUBLE_QUOTE:
			delegate.acceptDoubleQuote(ctx);
			break;

		case EQUALS:
			delegate.acceptEquals(ctx);
			break;

		case QUESTION_MARK_CLOSE_CHEVRON:
			delegate.acceptQuestionMarkCloseChevron(ctx);
			break;

		case ATTRIBUTE_VALUE:
			delegate.acceptAttributeValue(ctx);
			break;

		case SPACE:
			delegate.acceptSpace(ctx);
			break;

		case WHITESPACE:
			delegate.acceptWhitespace(ctx);
			break;
			
		default:
			throw new AssemblerException("Parser cannot handle token: " + ctx.getToken(), ctx.getLocation());
		}
	}
}
